Getting Started in CODESYS 4
The following guide describes the procedure how to create your first minimal project and download it to the controller.
The guide includes the following steps:
Starting CODESYS 4
Creating a workspace
Creating a device project
Setting up communication to the controller
Downloading and logging in to the application on the controller
Starting CODESYS 4
In the file explorer, open the installation directory of CODESYS 4.
Run the
CODESYS-4.exeprogram.The programming interface of CODESYS 4 will open.
Creating a workspace
Select the Menu → Create Workspace command or click the
icon.
In the Create Workspace dialog, choose the name and click the
button to select the location.Click OK.
The workspace will be created and opened.
The Add Project to Workspace dialog will open.
Creating a device project
In the Add Project to Workspace dialog, select the Create Device Project entry.
In the next dialog, specify the data for your new project and then click OK.
Click the
button to select the location.Choose the project name, for example
MyFirstProject.Specify values for all other parameters.
The version number must be a 3 or 4-part semver, for example
2.1.0or1.0.0.0.
In the Add PLC dialog, select the CODESYS Control Win V3 x64 controller.
Choose a name for the controller, for example
MyPLC, and click OK.In the Add program dialog, select Structured Text (ST) as the implementation language and click Create.
The wizard will close and the project items will be displayed in the workspace navigator.
The
Communication.settings.json,ProjectInfo.json,TaskConfiguration.json, andLibraries.jsonfiles will be automatically generated and displayed in the workspace navigator.Double-click the PLC_PRG item.
The PLC_PRG program will be opened in the editor.
Enter the following program into the editor:
PROGRAM PLC_PRG VAR iCounter: INT := 0; END_VAR // implementation here... iCounter := iCounter + 1; END_PROGRAMRight-click the
Libraries.jsonitem and run the Resolve All Libraries command.Check if errors are displayed in the LIBRARY RESOLUTION and PROBLEMS:LIBRARIES views.
Note: The PROBLEMS:LIBRARIES view will be displayed only if errors have actually occurred.
Right-click the
Application.iecappitem and select the Build Application command.In the BUILD output, check that the project has been compiled successfully.
Setting up communication to the controller
Double-click the
Communication.settings.jsonitem.The Communication Settings wizard will open in the editor.
Click the Configure Device button.
The Device Browser dialog will open.
Click the Add Gateway button.
Important
The controller must be running in order to set up the gateway.
In the Add Gateway dialog, choose a name for your gateway and click Add.
Note: The values for IP address and Port remain unchanged.
The gateway will be displayed in the Device Browser.
The available controllers will be displayed.
Click your controller to select it and click the Connect Device button.
Because a user management has not been set up on your device yet, the Create Initial User for Device dialog will open.
Choose a user name and password. Confirm the password and click Apply.
Note: The chosen password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one special character, and one digit.
In the Log In to Device dialog, provide your new credentials and click Log In.
The notification Connection successful will be displayed.
In the Device Browser dialog, click Select.
For more information, see the following: Communication.settings.json
Downloading and logging in to the application on the controller
Right-click the Application.iecapp application and select the Download Application command.
A notification will be displayed to indicate that existing applications on the controller will be overwritten. The application will be downloaded to the controller. The notification Download succeeded will be displayed.
Click the
icon (top right) or press the Alt+F8 shortcut to log in to the controller.The notification Login succeeded will be displayed.
Open the PLC_PRG program in the editor.
Click the
icon (top right) to run the program.
The inline monitoring in the editor will show the changing value of the
iCountervariable.Open the WATCHLIST view. For Expression, specify the value
PLC_PRG.iCounter.The changing value of the
iCountervariable will be displayed under Value.Click the
icon (top right) to stop the program.
Click the
icon (top right) or press the Ctrl+F8 shortcut to log out of the controller.The notification
Logout succeededwill be displayed.